/*###################################################################*
#
# MPGL Engine - CrossPlatform OpenGL Engine
# Copyright (C) 2014  Mitchell Pell
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
####################################################################*/

#ifndef GL_BITMAP_FONT_H
#define GL_BITMAP_FONT_H

//#### Includes

#include <fstream>
#include <string>
#if _WIN32
#include <windows.h>
#endif
#include <gl\gl.h>

//#### Blend flags

#define BFG_RS_NONE  0x0      
#define BFG_RS_ALPHA 0x1
#define BFG_RS_RGB   0x2
#define BFG_RS_RGBA  0x4

/*! Maximum string length */
#define BFG_STRARRAYSIZE	256
#define BFG_MAXSTRING		255   
/*! Offset to width data with BFF file */
#define WIDTH_DATA_OFFSET	20 
/*! Offset to texture image data with BFF file */
#define MAP_DATA_OFFSET		276 

//#### This definition is missing from some GL libs

#ifndef GL_CLAMP_TO_EDGE 
#define GL_CLAMP_TO_EDGE 0x812F 
#endif


namespace mpgl_engine{ namespace scene { namespace fonts {
	/*!----------------------------------------------------------------
	*	@class		GLBitmapFont
	*	@brief		
	*
	*	@author		Mitchell Pell
	*	@date		9/28/2013
	*	@version	1.0
	*
	----------------------------------------------------------------*/
	class GLBitmapFont
	{
		enum Coordinate
		{
			X = 0,
			Y = 1
		};
		enum ColorRGBA
		{
			R = 0,
			G = 1,
			B = 2,
			A = 3
		};

		int		m_cell[2];
		int		m_yOffset;
		int		m_rowPitch;
		char	m_base;
		char	m_width[BFG_STRARRAYSIZE];   
		GLuint	m_texID;
		int		m_cur[2];
		float	m_rowFactor;
		float	m_colFactor;
		int		m_renderStyle;
		float	m_clr[4];
		bool	m_invertYAxis;

	public:
		GLBitmapFont();
		~GLBitmapFont();
		bool Load(char *fname);
		void SetScreen(int x, int y); 
		void SetCursor(int x, int y); 
		void SetColor(float Red, float Green, float Blue, float Alpha);
		void ReverseYAxis(bool State);
		void Select();       
		void Bind();        
		void Unbind();
		void SetBlend();  
		void Print(const char *Text);       
		void Print(const char *Text, int x, int y);
		int  GetWidth(char *Text);
		int GetHeight(){return m_cell[Y];}

	};
}}}

#endif